var input = {
	init:function(){
		this.getdata();
		$('#maindiv').click(function(){
			$(this).removeClass('bixuform');
		});
	},
	save:function(){
		var o1 = get('btnsave');
		var da = js.getformdata();
		var i,len=fieldsarr.length,fid,frs,val;
		js.setmsg('');
		for(i=0;i<len;i++){
			frs = fieldsarr[i];
			fid = frs['fields'];
			val = da[fid];
			if(frs.isbt==1 && isempt(val)){
				this.showtishi(''+frs.name+'不能为空',fid);
				return;
			}
		}
		o1.disabled = true;
		js.setmsg('保存中...');
		
		js.ajax.post({
			url:'?m=input&a=save&num='+modenum+'&group='+modegroup+'&mid='+mid+'',
			data:da,
			btnobj:o1,
			onsuccess:function(ret){
				js.setmsg();
				input.savesuccess();
			},
			onerror:function(ret){
				js.setmsg(ret.msg);	
				o1.disabled = false;
			}
		});
	},
	showtishi:function(nr,fid){
		js.setmsg(nr);
		js.show.error(nr);
		$('#maindiv').addClass('bixuform');
	},
	savesuccess:function(){
		this.disabledform();
		try{
			if(opener.table){
				opener.table.reload();
				window.close();
			}
		}catch(e){}
	},
	getdata:function(){
		if(mid==0)return;
		var o1 = get('btnsave');
		o1.disabled = true;
		js.setmsg('加载数据中...');
		js.ajax.get({
			url:'?m=input&a=dataedit&num='+modenum+'&group='+modegroup+'&mid='+mid+'',
			onerror:function(ret){
				js.setmsg(ret.msg);
				input.disabledform();
			}
		},function(ret){
			o1.disabled = false;
			input.showdata(ret.data);
		});
	},
	showdata:function(da){
		js.setmsg();
		var data = da.data;
		var i,len= fieldsarr.length,fid,frs,val;
		for(i=0;i<len;i++){
			frs = fieldsarr[i];
			fid = frs['fields'];
			val = data[fid];
			this.setvalue(frs, val);
		}
	},
	setvalue:function(frs, val){
		var fid = frs['fields'],type = frs['fieldstype'];
		var obj = jsform(fid),ovt;
		if(!obj || typeof(val)=='undefined')return;
		if(type=='checkbox'){
			if(val=='1')obj.checked = true;
		}else{
			if(frs['isjm']==1)val = jm.base64decode(val);
			obj.value = val;
			if(type=='uploadimg' && val){
				ovt = get(''+fid+'_id_img');
				if(ovt)ovt.src = val;
			}
		}
	},
	disabledform:function(){
		$(document['myform']).find('*').attr('disabled', true);
	},
	uploadimg:function(na,fid){
		js.updateface(na,fid);
	},
	uploadclear:function(fid){
		if(get(fid))get(fid).value='';
		if(get(fid+'_img'))get(fid+'_img').src=''+urlstatic+'webstatic/images/noimg.jpg';
	}
}
function initbody(){
	input.init();
}